beautiful binary string hackerrank solution in python